package com.chencs.app.lianmeng.service;


import com.chencs.app.AppCommon;
import com.chencs.app.lianmeng.mapper.LMSubjectMapper;
import com.chencs.vo.biz.lianmeng.LmProduct;
import com.chencs.vo.biz.lianmeng.LmSubject;
import com.chencs.vo.net.lmrequest.LmSubjectListRequest;
import com.chencs.vo.net.lmrequest.LmSubjectRequest;
import com.chencs.vo.net.lmresponse.LmSubjectListResponse;
import com.chencs.vo.net.lmresponse.LmSubjectResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LMSubjectSer {


    @Autowired
    private LMSubjectMapper mapper;

    /**
     * 获取专题详情
     * @param request
     * @return
     */
    public LmSubjectResponse getSubject(LmSubjectRequest request){
        LmSubjectResponse response = new LmSubjectResponse();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("pageno",request.getPageNo()*request.getPageSize());
        map.put("pagesize",request.getPageSize());

        System.out.println(map.toString());
        List<LmSubject> lmSubjects = mapper.getSubject(map);
        if(CollectionUtils.isEmpty(lmSubjects)){
            response.setCode(AppCommon.NULL);
            response.setMsg(AppCommon.NULLMSG);
        }else{
            response.setLmSubject(lmSubjects);
            response.setMsg(AppCommon.SUCCESSMSG);
            response.setCode(AppCommon.SUCCESS);
        }
        return  response;
    }


    /**
     * 获取专题详情
     * @param request
     * @return
     */
    public LmSubjectListResponse getSubjectItem(LmSubjectListRequest request){
        LmSubjectListResponse response = new LmSubjectListResponse();
        List<LmProduct> lmsList = mapper.getSubjectProBySid(request.getSubjectId());
        if(CollectionUtils.isEmpty(lmsList)){
            response.setCode(AppCommon.NULL);
            response.setMsg(AppCommon.NULLMSG);
        }else{
            response.setSubjectList(lmsList);
            response.setMsg(AppCommon.SUCCESSMSG);
            response.setCode(AppCommon.SUCCESS);
        }
        return  response;
    }

}

